package sample;

import com.google.common.base.Strings;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Control;
import javafx.scene.control.TextField;

import java.util.List;

/**
 * Created by lilongfei on 2016/12/16.
 */
public class CheckInfo {

    public static boolean check(List<Control> list){
        for(Control control : list){
            if(!checkNull(control)){
                return false;
            }
        }
        return true;
    }

    private static boolean checkNull(Control control){

        if (control instanceof TextField){
            if(Strings.isNullOrEmpty(((TextField) control).getText())){
                control.requestFocus();
                return false;
            }
        }else if(control instanceof ChoiceBox){
            if(((ChoiceBox) control).getValue() == null){
                control.requestFocus();
                return false;
            }
        }
        return true;
    }
}
